<?php
require_once './libraries/utilities/functions.php';
$path ='../ptnhuan-web1/data/films.txt';
$full_path = realpath($path);
$films = mreadFile($path);
?>
<form method="POST" > 
    <?php
    for($i =0 ;$i <count($films) ; $i ++) {
        $a = trim($films[$i], '\n\t\r ');
        $film = explode(";", $a);
        if ($_GET["if"] == $film[0]) {
            ?>
            <img src = '../ptnhuan-web1/public/images/films/<?php if (!empty($film[1])) echo $film[1] ?>'/> </br>
            Film Name   :<input type="text" name="name" value="<?php if (!empty($film[2])) echo $film[2] ?>">
            Rating   :<input type="text" name="namea" value="<?php if (!empty($film[3])) echo $film[3] ?>"> </br>
            Comment: <textarea name="comment" rows="6" cols="35"></textarea></br>
            <input type="submit" name="submit" value="save">
        <?php }
    }
    ?>
</form>
<a href="films.php">Goback</a>


<?php
if (isset($_POST["submit"])) {
    for ($i = 0; $i < count($films); $i++) {
        $b = trim($films[$i], " \t\n\r");
        if (!empty($b)) {
            $films[$i] = explode(";", $b);
            if ($_GET["if"] == $films[$i][0]) {
                $films[$i][2] = $_POST["name"];
                $films[$i][3] = $_POST["namea"];
            }
        } else {
            $films[$i] = $b;
        }
    }
    mwriteFile($films);
}
?>

